    <div class="row">
		  <div class="col-xs-6 col-md-3">
		    
		  </div>
		  <div class="col-xs-6 col-md-9">
		  		<button onclick="location_add();" class="btn btn-success pull-right">新增</button>
		  </div>
		</div>
          <div class="table-responsive">
            <table class="table table-striped">
              <thead>
                <tr>
                  <th>排序</th>
                  <th>名称</th>
                  <th>语言</th>
                  <th>货币</th>
                  <th width="150">操作</th>
                </tr>
              </thead>
              <tbody>
              	<?php foreach ($list as $item):?>
                  <tr id="location_<?=$item['id']?>">
                      <td><input class="location_sort" style="border:none" location_id="<?=$item['id']?>" location_mark="<?=$item['order']?>" type="number" value="<?=$item['order']?>" min=0 max=1000 /></td>
                      <td><?=$item['name']?></td>
                      <td data-lang-id="<?=$item['lang_id']?>"><?=$item['lang']?></td>
                      <td data-currency-id="<?=$item['currency_id']?>"><?=$item['currency']?></td>
                      <td>
                          <div class="btn-group" role="group" aria-label="...">
                            <button type="button" onclick="location_edit(<?=$item['id']?>,'<?=$item['name']?>');" class="btn btn-primary btn-sm">编辑</button>
                            <button type="button" onclick="location_delete(<?=$item['id']?>);" class="btn btn-danger btn-sm">删除</button>
                          </div>
                      </td>
                  </tr>
              <?php endforeach;?>
              </tbody>
            </table>
          </div>
    
 <script type="text/javascript">
$(function(){
    $('.location_sort').blur(function(){
      var input = $(this);
      var newVal = input.val();
      var oldVal = input.attr('location_mark');
      var id = input.attr('location_id');
      if(newVal!=oldVal){
        var loading = layer.load(1, {
          shade: [0.5,'#000']
        });
        $.post('',{order:newVal,id:id},function(result){
          if(result.statu=='ok'){
            location.reload();
          }else{
            layer.close(loading);
            layer.msg(result.message, {icon: 2});
            input.val(oldVal);
          }
        },'json')
      }
    })
 })

function location_delete(id){
  var confirm = layer.confirm('确定删除？', {
    btn: ['确定','取消'] //按钮
  }, function(){
    layer.close(confirm);
    var loading = layer.load(1, {
      shade: [0.5,'#000']
    });
    $.post('',{id:id},function(result){
      if(result.statu=='ok'){
        location.reload();
      }else{
        layer.close(loading);
        layer.msg(result.message, {icon: 2});
      }
    },'json')
  });
}

function location_form(data){
  if(!data) data = {name:'',lang_id:'',currency_id:''};
  data.lang_option = <?=$lang_option?>;
  data.currency_option = <?=$currency_option?>;
  var html = '<form id="location_form">';
  if(data.id) html+='<input type="hidden" name="id" value="'+data.id+'" />';
  html+=makeInput({name:'name',label:'地区名称',value:data.name});
  html+=makeInput({name:'lang_id',label:'语言',value:data.lang_id,option:data.lang_option,type:'select'});
  html+=makeInput({name:'currency_id',label:'货币',value:data.currency_id,option:data.currency_option,type:'select'});
  html+='</form>';
  return html;
}

function location_edit(id){
  var $td = $('#location_'+id).children('td');
  var data = {id:id};
  data.name = $td.eq(1).text();
  data.lang_id = $td.eq(2).data('lang-id');
  data.currency_id = $td.eq(3).data('currency-id');
  var html = location_form(data);
  $.alert('修改地区',html,function(modal){
    var formData = $("#location_form").serializeJson();
    formData.name = $.trim(formData.name);
    if(formData.name.length<1||formData.name.length>20){
      $('#alert_form_name').formTip('地区名称长度为1-20！','error',false);
      return
    }
    var loading = layer.load(1, {
      shade: [0.5,'#000']
    });
    $.post('',formData,function(result){
      if(result.statu=='ok'){
        location.reload()
      }else{
        layer.close(loading);
        layer.msg(result.message, {icon: 2});
      }
    })
    modal.modal('hide');
  },function(modal){
    modal.modal('hide');
  });  
}


function location_add(){
  var html = location_form();
  $.alert('增加地区',html,function(modal){
    var formData = $("#location_form").serializeJson();
    formData.name = $.trim(formData.name);
    if(formData.name.length<1||formData.name.length>20){
      $('#alert_form_name').formTip('地区名称长度为1-20！','error',false);
      return
    }
    var loading = layer.load(1, {shade: [0.5,'#000']});
    $.post('',formData,function(result){
      if(result.statu=='ok'){
        location.reload()
      }else{
        layer.close(loading);
        layer.msg(result.message, {icon: 2});
      }
    })
    modal.modal('hide');
  },function(modal){
    modal.modal('hide');
  }); 
}
</script>
        